// 添加/编辑排行榜时，初始化年份月份季度的下拉菜单数据

/** 为一个年份的下拉菜单提供数据，从开始年份数字到当前年份
 * @param {Number} 开始年份数字
 * @returns {Array}
 */
export function setDdlYear(startNum) {
  const result = []
  result.push({
    value: 0,
    label: '选择年份',
  })
  if (!(startNum && startNum > 0)) startNum = 1970
  for (let i = startNum; i <= new Date().getFullYear(); i++) {
    const temp = {
      value: 0,
      label: '',
    }
    temp.label = i + '年'
    temp.value = i
    result.push(temp)
  }
  return result
}

/** 为一个月份的下拉菜单提供数据，从1到12
 * @returns {Array}
 */
export function setDdlMonth() {
  const result = []
  result.push({
    value: 0,
    label: '选择月份',
  })
  for (let i = 1; i <= 12; i++) {
    const temp = {
      value: 0,
      label: '',
    }
    temp.label = i + ' 月份'
    temp.value = i
    result.push(temp)
  }
  return result
}

/** 为一个季度的下拉菜单提供数据，从1到4
 * @returns {Array}
 */
export function setDdlQuarter() {
  const result = []
  result.push({
    value: 0,
    label: '选择季度',
  })
  for (let i = 1; i <= 4; i++) {
    const temp = {
      value: 0,
      label: '',
    }
    temp.label = i + ' 季度'
    temp.value = i
    result.push(temp)
  }
  return result
}

/** 根据年份、月份、季度等下拉菜单设置日期范围，比如(2020,4,3)得到2020年二季度的日期数组
 * @param {Number} year 年份
 * @param {Number} monthStart 开始月份
 * @param {Number} diff 偏移值
 * @returns {Array}
 */
export function setDateRange(year, monthStart, diff) {
  const range = []
  const dtStart = year + '/' + monthStart + '/1 00:00:00'
  let monthEnd = 0
  if (monthStart + diff >= 12) {
    year += 1
    monthEnd = monthStart + diff - 12
  } else {
    monthEnd = monthStart + diff
  }
  const dtEnd = year + '/' + monthEnd + '/1 00:00:00'
  range.push(new Date(dtStart))
  range.push(new Date(dtEnd))
  console.log('range', range)
  return range
}
